{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import atx\n",
    "from atx.ext.report import Report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{u'build': {u'time': u'Aug 24 2016 16:14:32'},\n",
       " u'ios': {u'simulatorVersion': u'9.3.2'},\n",
       " u'os': {u'name': u'iPhone OS', u'version': u'9.3.2'},\n",
       " u'state': u'success'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = atx.connect('http://127.0.0.1:8100')\n",
    "d.status()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<wda.Session at 0x10c6f5890>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.start_app('com.supercell.magic')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.rotation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "rp = Report(d)\n",
    "rp.patch_wda()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Display(width=640, height=1136)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "320"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.display\n",
    "print d.display\n",
    "min(d._session.window_size())\n",
    "#d.click(100, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-08-24 16:20:57.908 INFO  [atx.drivers.mixin: 598] click image: Pattern(name: ./train.2208x1242.png, offset: None)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "FindPoint(pos=(46, 465), confidence=0.9747188091278076, method='template', matched=True)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.click_image('train.2208x1242.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-08-24 16:21:03.833 INFO  [atx.drivers.mixin: 598] click image: Pattern(name: ./left.2208x1242.L170T6.png, offset: (-1.7, -0.06))\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "FindPoint(pos=(135, 297), confidence=0.94251549243927, method='template', matched=True)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.click_image('left.2208x1242.L170T6.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-08-24 15:08:19.753 INFO  [atx.drivers.mixin: 598] click image: Pattern(name: ./left.2208x1242.L170T6.png, offset: (-1.7, -0.06))\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "FindPoint(pos=(135, 296), confidence=0.9492990374565125, method='template', matched=True)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.click_image('left.2208x1242.L170T6.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-08-24 15:08:23.173 INFO  [atx.drivers.mixin: 598] click image: Pattern(name: ./girl.2208x1242.png, offset: None)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "FindPoint(pos=(365, 322), confidence=0.9324912428855896, method='template', matched=True)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.click_image('girl.2208x1242.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2016-08-24 15:08:26.071 INFO  [atx.drivers.mixin: 598] click image: Pattern(name: ./exit.2208x1242.png, offset: None)\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "FindPoint(pos=(947, 39), confidence=0.9356588125228882, method='template', matched=True)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d.click_image('exit.2208x1242.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "d.stop_app()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "rp.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'PORTRAIT'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d._session.orientation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
